package titt.server.func;

import titt.head.HeadFactory;
import titt.head.request.MethodHead;
import titt.head.response.ResponseHead;
import titt.io.socket.TITTSocket;
import titt.key.TITTKey;
import titt.server.os.ObjectServer;
import titt.server.os.ServerValueConfig;

public class ServiceUnregistration implements TITTFunction {

	public String getMethodName() {
		return "unregister";
	}

	public void handle(TITTKey key, MethodHead head, TITTSocket ts, ObjectServer os) throws Exception {

		String serviceID = head.getParams()[0].getObject();

		boolean lazy = false;
		if(head.getParams().length > 1)
			lazy = head.getParams()[1].getObject();

		os.getServerInternal().unregister(serviceID, lazy? ServerValueConfig.get().getTimeout() : 0);

		ts.getHeadWriter().writeHead(new ResponseHead(200, HeadFactory.EMPTY));
		ts.close();
	}

}
